<template>
  <el-tree
  :props="props"
  :load="loadNode"
  lazy
  @node-click="clickHandle"
  accordion
  >
</el-tree>
</template>

<script>
import LoginVue from '@/views/login/Login.vue';
  export default {
    data() {
      return {
        props: {
          label: 'name',
          children: 'zones',
          isLeaf: 'leaf'
        },
        treeData:[]
      };
    },
    methods: {
      clickHandle(data,node){
          console.log(data,node);
          this.$emit('sendTreeData',data)
      },
      loadNode(node, resolve) {
        if (node.level === 0) {
          this.$api.selectItemCategoryByParentId()
                    .then(res => {
                        if (res.data.status == 200) {
                            return resolve(res.data.result);
                        }else{
                            return resolve([])
                        }
                    })
        }
        if (node.level >= 1) {
             //请求--------
                this.$api.selectItemCategoryByParentId({type:node.data.cid})
                    .then(res => {
                        if (res.data.status == 200) {
                            return resolve(res.data.result);
                        }else{
                            return resolve([])
                        }
                    })
        }
      },
      // //请求商品的类目
      // async selectItemCategoryByParentId(type){
      //   let res = await this.$api.selectItemCategoryByParentId({type})
      //   console.log(res.data);

      // }
    },

  };
</script>

<style>

</style>